import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Enemigo3 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Enemigo3 extends Enemigo
{
    private final static int IMAGE_COUNT= 2;
    private static GreenfootImage[] imgs;
    private int x=0,z=5;
    private int invi=0;
    /*
     * Act - do whatever the Enemigo3 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public Enemigo3()
    {
     init();
     setImage(imgs[0]);
    }
    
    public void act() 
    {  
        setImage(imgs[0]);
        Aspire w = (Aspire)getWorld();
        Mueve();
        Mueve1();
        w.retx(getX());
        Dispara(3);
        if(Greenfoot.getRandomNumber(900)==4)
        invi=300;
        if(invi<1)
         Interseccion();
        else
        {
         invi--;
         setImage(imgs[1]);
        }
      }
    
    /**
     * En este enemigo se mueve pero a lavez cuando el jugador va presionando la tecla
     */
    public void Mueve()
    {
    
         if (Greenfoot.isKeyDown("left"))
         {
             x=getX()-2;
            if(x<=1)
              x=getWorld().getWidth()-1;
              setLocation(x,getY());
         }
        
        if (Greenfoot.isKeyDown("right"))
        {
           x=getX()+2;
             if(x>= getWorld().getWidth()-1)
              x=0;
           setLocation(x,getY());
           
        }
        
    }
    
    /**
     * Se mueve el enemigo
     */
    public void Mueve1()
    {
        int yAux;
        yAux=getY()+2;
        if(yAux >= getWorld().getHeight()-1)
          yAux=0;
        setLocation(getX(),yAux);
        }
    
    /**
     * Checa si ay interseccion con otros objetos
     */
    public void Interseccion()
    {
        Aspire w = (Aspire)getWorld();
        Actor balap = getOneIntersectingObject(Balapc.class);
        Actor balpo = getOneIntersectingObject(bapc.class);
        Actor bala = getOneIntersectingObject(Balajug.class);
        Actor balapo = getOneIntersectingObject(Balapod.class);
        
        if (balap != null)
        {
           Greenfoot.playSound("hit.wav");
           hit--;
          if(hit<=5)
          {
            w.addScorep(30);
            destroy();
          }
          
           
        }
        
        if (balpo != null)
        {
           Greenfoot.playSound("hit.wav");
           hit-=3;
          if(hit<=5)
          {
            w.addScorep(30);
            destroy();
          }
          
           
        }
        
        if (bala!= null)
        {
           Greenfoot.playSound("hit.wav");
           hit--;
          if(hit<=5)
          {
            w.addScore(30);
            destroy();
          }
          
           
        }
        if (balapo!= null)
        {
           Greenfoot.playSound("hit.wav");
           hit-=3;
          if(hit<=5)
          {
            w.addScore(30);
            destroy();
          }
          
           
        }
    } 
    
    private synchronized static void init() 
    {
        if(imgs == null) {
            imgs = new GreenfootImage[IMAGE_COUNT];
            for (int i = 0; i < IMAGE_COUNT; i++)
            {
            imgs[i] = new GreenfootImage("enemy3"+ (i+1) + ".png");
            
        }
        }
    }
    }

    
